package com.gaojiawei.multiThread11_ThreadPoolJDk;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class L04_ScheduledThreadPool {
    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);

        //正常执行
        scheduledExecutorService.execute(()->{
            System.out.println("normal user");
        });

        //延迟时间后执行
        scheduledExecutorService.schedule(()->{
            System.out.println("delay use");
        },5,TimeUnit.SECONDS);

        //周期执行 计算任务时间
        scheduledExecutorService.scheduleAtFixedRate(()->{
            System.out.println("周期执行");
        },5,3,TimeUnit.SECONDS);

        //不计算任务时间，下次执行时间从，上次执行任务结束后开始计算
        scheduledExecutorService.scheduleWithFixedDelay(()->{
            System.out.println("周期执行");
        },5,3,TimeUnit.SECONDS);
    }
}